package org.ouwa.lms.client.ui.student;

import org.ouwa.lms.client.manager.ManagerRegistry;
import org.ouwa.lms.client.model.Account;
import org.ouwa.lms.client.support.event.ApplicationEvent;
import org.ouwa.lms.client.support.event.ApplicationEventListener;
import org.ouwa.lms.client.ui.EventPane;
import org.ouwa.lms.client.ui.HeaderPane;
import org.ouwa.lms.client.ui.event.LogoutEvent;

import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.VerticalPanel;

public class StudentMain extends EventPane {
	private static final String MAIN_URL = "http://ouwa.lnys.per.sg/video.5.html";
	private static final String MAIN_STYLE = "frame";
	private static final int MAIN_HEIGHT = 680;
	
	private final Account account;
	private HeaderPane headerPane;
	
	public StudentMain(ManagerRegistry managerRegistry, Account account) {
		super(managerRegistry);
		this.account = account;
		
		VerticalPanel mainPanel = new VerticalPanel();
		mainPanel.setSize("90%", "100%");
		mainPanel.setStyleName("wrapper");
		mainPanel.setSpacing(10);
		
		headerPane = new HeaderPane(managerRegistry, account);
		headerPane.addListener(new LogoutEventListener());
		headerPane.setWidth("100%");
		mainPanel.add(headerPane);
		
		Frame mainFrame = new Frame(MAIN_URL);
		mainFrame.setSize("100%", MAIN_HEIGHT + "px");
		mainFrame.setStyleName(MAIN_STYLE);
		mainPanel.add(mainFrame);
		
		initWidget(mainPanel);
	}
	
	protected class LogoutEventListener implements ApplicationEventListener {
		@Override
		public void handle(ApplicationEvent event) {
			if(event instanceof LogoutEvent) {
				fireEvent(event);
			}
		}
	}
}
